package jena.examples.rdf ;



import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.util.PrintUtil;
import com.hp.hpl.jena.vocabulary.RDFS;

// example of how to use JENA

public class TestCommunication {

	public static void main(String[] args) {
		// Create an empty in-memory model and populate it from the graph
		Model model = ModelFactory.createDefaultModel();

		model.read("file:/Users/DANsarti/TBCFreeWorkspace/sarti/comm.owl");
		
		System.out.println("using SPARQL");
		// Create a new query
		String queryString = 
			"SELECT  ?datagram ?position "+
			"WHERE { ?datagram <"+
			Communication.hasDatagramVariable + "> ?s. ?s <"  +
			Communication.hasBaseVariable + "> <"+
			Communication.sea_water_temperature +"> . ?s <"+
			Communication.isAtPosition +"> ?position ."+
			"      }";

		
		Query query = QueryFactory.create(queryString);

		// Execute the query and obtain results
		QueryExecution qe = QueryExecutionFactory.create(query, model);
		ResultSet results = qe.execSelect();

		// Output query results	
		//System.out.println("**"+ResultSetFormatter.asXMLString(results));
	    ResultSetFormatter.out(System.out, results, query);
		
		// Important - free up resources used running the query
		qe.close();
		
		
	}

}
